package com.muqi.app.qlearn.student.wxapi;

import com.muqi.app.project.contants.MContants;
import com.muqi.app.project.utils.ShowToast;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
	// IWXAPI 是第三方app和微信通信的openapi接口
	private IWXAPI api;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		api = WXAPIFactory.createWXAPI(this, MContants.WX_APP_ID, true);
		api.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq arg0) {
	}
	@Override
	public void onResp(BaseResp resp) {
		switch (resp.errCode) {
		case BaseResp.ErrCode.ERR_OK:
			ShowToast.showShort(this,"分享成功");
			WXEntryActivity.this.finish();
			// 分享成功
			break;
		case BaseResp.ErrCode.ERR_USER_CANCEL:
			ShowToast.showShort(this, "分享取消");
			WXEntryActivity.this.finish();
			// 分享取消
			break;
		case BaseResp.ErrCode.ERR_AUTH_DENIED:
			ShowToast.showShort(this, "分享被拒绝");
			WXEntryActivity.this.finish();
			// 分享拒绝
			break;
		default:
			ShowToast.showShort(this, "分享异常");
			WXEntryActivity.this.finish();
			break;
		}
	}
}
